package com.bs.regsystemapi.entity;

import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * @author ning
 * @date 2022-12-29 17:50
 * @description 封装返回结果
 */
public class Result<T> implements Serializable {
    /**
     * 执行结果，true为执行成功 false为执行失败
     */
    @ApiModelProperty("执行结果，true为执行成功 false为执行失败")
    private boolean flag;

    /**
     * 返回提示信息，主要用于页面提示信息
     */
    @ApiModelProperty("返回提示信息，主要用于页面提示信息")
    private String message;

    /**
     * 返回数据
     */
    @ApiModelProperty("返回数据")
    private T data;

    public Result() {
    }

    public Result(boolean flag, String message) {
        super();
        this.flag = flag;
        this.message = message;
    }
    public Result(boolean flag, String message, T data) {
        this.flag = flag;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success(T data, String message) {
        Result<T> result = new Result<T>();
        result.data = data;
        result.message = message;
        result.flag = true;
        return result;
    }

    public static <T> Result<T> success(String message) {
        Result<T> result = new Result<T>();
        result.message = message;
        result.flag = true;
        return result;
    }

    public static <T> Result<T> error(String message) {
        Result<T> result = new Result<T>();
        result.message = message;
        result.flag = false;
        return result;
    }

    public boolean isFlag() {
        return flag;
    }
    public void setFlag(boolean flag) {
        this.flag = flag;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    public Object getData() {
        return data;
    }
    public void setData(T data) {
        this.data = data;
    }
}
